package com.ykzb.project.model;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;

import com.ykzb.enums.QiniuBucket;
import com.fasterxml.jackson.annotation.JsonIgnore;

public class ProjectInfo implements Serializable{

	private long id;

	/** 项目ID **/
	private String projectCode;

	/** 项目标题 **/
	private String projectTitle;

	/** 项目状态 **/
	private int projectStatus;

	/** 项目类型：转让或招标 **/
	private int projectType;

	/** 发布金额 **/
	private BigDecimal projectMoney;

	/** 投标数 **/
	private int goodsNum;

	/** 项目周期 **/
	private int dayNum;

	/** 感兴趣人数 **/
	private int viewNum;

	/** 分类ID **/
	private long categoryId;

	/** 分类名 **/
	private String categoryName;

	/** 需求描述 **/
	private String description;

	/** 专利所属单位 **/
	private String unit;

	/** 项目简介 **/
	private String brief;

	@JsonIgnore
	private String avatarKey;

	@JsonIgnore
	private int avatarKeyVersion;

	/** 项目发布人信息 **/
	private long ownerId;



	/**七牛图片路径**/
	private String projectImg;


	public void setDayNum(int dayNum) {
		this.dayNum = dayNum;
	}


	/**
	 * 通过七牛Key生成图片URI
	 * @return
	 */
	private String getProjectImgUrl() {
		if (StringUtils.isNotBlank(avatarKey)) {

			Pattern p = Pattern.compile("^http://.*|^https://.*");
            Matcher m = p.matcher(avatarKey);
            if (m.matches()) {
                return avatarKey;
            }

            return QiniuBucket.HEAD_IMG.getDomain() + avatarKey + "?v=" + avatarKeyVersion;
        }
        return "";
    }

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getProjectCode() {
		return projectCode;
	}

	public void setProjectCode(String projectCode) {
		this.projectCode = projectCode;
	}

	public String getProjectTitle() {
		return projectTitle;
	}

	public void setProjectTitle(String projectTitle) {
		this.projectTitle = projectTitle;
	}

	public int getProjectStatus() {
		return projectStatus;
	}

	public void setProjectStatus(int projectStatus) {
		this.projectStatus = projectStatus;
	}

	public int getProjectType() {
		return projectType;
	}

	public void setProjectType(int projectType) {
		this.projectType = projectType;
	}

	public BigDecimal getProjectMoney() {
		return projectMoney;
	}

	public void setProjectMoney(BigDecimal projectMoney) {
		this.projectMoney = projectMoney;
	}

	public int getGoodsNum() {
		return goodsNum;
	}

	public void setGoodsNum(int goodsNum) {
		this.goodsNum = goodsNum;
	}

	public Integer getDayNum() {
		return dayNum;
	}

	public void setDayNum(Integer dayNum) {
		this.dayNum = dayNum;
	}

	public int getViewNum() {
		return viewNum;
	}

	public void setViewNum(int viewNum) {
		this.viewNum = viewNum;
	}

	public long getCategoryId() {
		return categoryId;
	}

	public void setCategoryId(long categoryId) {

		this.categoryId = categoryId;
	}

	public String getCategoryName() {
		return categoryName;
	}

	public void setCategoryName(String categoryName) {
		this.categoryName = categoryName;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getUnit() {
		return unit;
	}

	public void setUnit(String unit) {
		this.unit = unit;
	}

	public String getBrief() {
		return brief;
	}

	public void setBrief(String brief) {
		this.brief = brief;
	}

	public String getAvatarKey() {
		return avatarKey;
	}

	public void setAvatarKey(String avatarKey) {
		this.avatarKey = avatarKey;
		if (StringUtils.isNotBlank(avatarKey)) {
			Pattern p = Pattern.compile("^http://.*|^https://.*");
			Matcher m = p.matcher(avatarKey);
			if (m.matches()) {
				this.projectImg = avatarKey;
			}else{
				this.projectImg = QiniuBucket.HEAD_IMG.getDomain() + avatarKey + "?v=" + avatarKeyVersion;
			}
		}
	}

	public int getAvatarKeyVersion() {
		return avatarKeyVersion;
	}

	public void setAvatarKeyVersion(int avatarKeyVersion) {
		this.avatarKeyVersion = avatarKeyVersion;
	}

	public long getOwnerId() {
		return ownerId;
	}

	public void setOwnerId(long ownerId) {
		this.ownerId = ownerId;
	}


	public String getProjectImg() {
		return projectImg;
	}

	public void setProjectImg(String projectImg) {
		this.projectImg = projectImg;
	}

}
